﻿using Application.Purchase_hService;
using AutoMapper;
using Domain.Entity.ord;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Purchase_dService
{
    public class Purchase_dService : IPurchase_dService
    {
        private readonly IPurchase_dRepository purchase_DRepository;
        private readonly IMapper mapper;

        public Purchase_dService(IPurchase_dRepository purchase_DRepository,IMapper mapper)
        {
            this.purchase_DRepository = purchase_DRepository;
            this.mapper = mapper;
        }

        //新增进货明细单
        public async Task<int> AddPurchase_d(AddPurchase_dDto addPurchase_DDto)
        {
            //转换
            Purchase_d purchase_D = mapper.Map<Purchase_d>(addPurchase_DDto);
            return await purchase_DRepository.AddPurchase_d(purchase_D);
        }

        //删除进货明细单
        public async Task<int> DeletePurchase_d(int purid)
        {
            return await purchase_DRepository.DeletePurchase_d(purid);
        }


        //根据进货单与货品获取到主键id
        public async Task<int> Getid(int purid, int procid)
        {
            return await purchase_DRepository.Getid(purid, procid);
        }

        //根据进货单id查询明细
        public async Task<List<Purchase_d>> GetPurchase_Ds(int purid)
        {
            return await purchase_DRepository.GetPurchase_Ds(purid);
        }

        //更新入库数量
        public async Task<int> Updatenum(UpdatedNum updateNum)
        {
            Purchase_d purchase_D=mapper.Map<Purchase_d>(updateNum);
            return await purchase_DRepository.Updatenum(purchase_D);
        }


        //更新已退货数量
        public async Task<int> UpdateRNum(int purtid, int returnnum)
        {
            return await purchase_DRepository.UpdateRNum(purtid, returnnum);
        }

        public async Task<int> UpdateRNum(int purtid, int returnnum, int newnum)
        {
            return await purchase_DRepository.UpdateRNum(purtid,returnnum,newnum);
        }
    }
}
